﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.IotInfo.SmartGarbageCan
{
    public class SmartGarbageCanService:ISmartGarbageCanService
    {
        private readonly IRepository<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan> _SmartGarbageCanService;

        public SmartGarbageCanService(IRepository<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan> SmartGarbageCanService)
        {
            _SmartGarbageCanService = SmartGarbageCanService;
        }
        //智能垃圾桶表显示
        public async Task<Response<List<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>>> GetSmartGarbageCanAsync()
        {
            var SmartGarbageCans = await _SmartGarbageCanService.GetAllListAsync();
            var result = SmartGarbageCans.MapToList<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>();
            return Response<List<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>>.Ok(result);
        }
        //智能垃圾桶表显示根据设备id查询
        public Response<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan> GetSmartGarbageCanData(Domain.IotInfo.SmartGarbageCans.SmartGarbageCan input)
        {
            var SmartGarbageCans = _SmartGarbageCanService.GetListQuery().FirstOrDefault(m => m.Id.ToString() == input.EquipmentNum);
            var result = SmartGarbageCans.MapTo<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>();
            return Response<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>.Ok(result);
        }
        //智能垃圾桶添加
        public async Task<Response<bool>> SmartGarbageCanAdd(Domain.IotInfo.SmartGarbageCans.SmartGarbageCan input)
        {
            var result = _SmartGarbageCanService.InsertAsyncById(input.MapTo<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>());

            return Response<bool>.Ok(result.Result > 0);
        }
        //智能垃圾桶删除
        public async Task<Response<bool>> SmartGarbageCanDelete(Domain.IotInfo.SmartGarbageCans.SmartGarbageCan input)
        {
            var result = await _SmartGarbageCanService.DeleteByIdAsync(input.MapTo<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>());
            return Response<bool>.Ok(result > 0);
        }
        //智能垃圾桶修改
        public async Task<Response<bool>> SmartGarbageCanUpdate(Domain.IotInfo.SmartGarbageCans.SmartGarbageCan input)
        {
            var result = _SmartGarbageCanService.UpdateAsync(input.MapTo<Domain.IotInfo.SmartGarbageCans.SmartGarbageCan>());

            return Response<bool>.Ok(result.Result > 0);
        }
    }
}
